export function getuInfo() {
    var data = [];
    return new Promise((resolve, reject) => {
        wx.getStorage({
            key: "user_token",
            success: res => {
                data.push(res.data)
                wx.getStorage({
                    key: "user_id",
                    success: res => {
                        data.push(res.data)
                        if (res.data) {
                            resolve(data);
                        }
                    }
                });
            }
        });
    });
}
export function alayer(main) {
    wx.showToast({
        title: main,
        icon: "none",
        duration: 2000
    });
}
export function formatTime(date) {
    let ist = isToday(date);

    if (ist == 0) {
        return isnow(date * 1000)
    }
    else {
        date = new Date(date * 1000);//根据后台为秒或者毫秒判断，秒需*1000
        var year = date.getFullYear()
        var month = date.getMonth() + 1
        var day = date.getDate()

        var hour = date.getHours()
        var minute = date.getMinutes()
        var second = date.getSeconds()
        return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
    }
}

function formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
}
function isToday(str) {
    if (new Date(str * 1000).toDateString() === new Date().toDateString()) {
        //今天
        return 0
    } else if (new Date(str) < new Date()) {
        //之前
        return 1
    }
}
function isnow(timestamp) {
    // 补全为13位
    var arrTimestamp = (timestamp + '').split('');
    for (var start = 0; start < 13; start++) {
        if (!arrTimestamp[start]) {
            arrTimestamp[start] = '0';
        }
    }
    timestamp = arrTimestamp.join('') * 1;
    let minute = 1000 * 60;
    let hour = minute * 60;
    let day = hour * 24;
    let halfamonth = day * 15;
    let month = day * 30;
    let now = parseInt(new Date().getTime() / 1000)
    let diffValue = now - timestamp/1000;
    // 计算差异时间的量级
    let minC = diffValue / minute;
    if (diffValue<120 ) {
        return  "1分钟前";
    }
    else {
        let timtte = new Date(timestamp);//根据后台为秒或者毫秒判断，秒需*1000
        let hour = timtte.getHours();
        let minute = timtte.getMinutes();
        return [hour, minute].map(formatNumber).join(':')

    }
};